#ifndef IMU_CAPTURE_H
#define IMU_CAPTURE_H

#include <iostream>
#include <fstream>
#include <chrono>
#include <algorithm>
#include <unistd.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <string.h>
#include <map>
#include <mutex>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <math.h>
#include <thread>
#include <sys/types.h>
#include <dirent.h>

#include "wit_c_sdk.h"


class ImuCapture
{
public:
	ImuCapture();

	~ImuCapture();

	int ttyConfigure(char *ttyPort, char *baudrate);

	bool imuInit();

	void imuSerialWrite(uint8_t* data, uint32_t len);

	void imuSerialRead();

	bool AutoScanSensor();

	void imuDataUpdata(uint32_t uiReg, uint32_t uiRegNum);

	typedef void (*imuDataCallback)(float accX, float accY, float accZ,
										float gyroX, float gyroY, float gyroZ, long long timestamp);

	bool registerimuDataCallback(imuDataCallback function);
private:
	int m_ttyFd;
	bool m_imuCaptureFlag;
	volatile char m_cDataUpdate;
	volatile char m_cCmd;

	imuDataCallback m_imuDataCallbackFunction;

	float m_fAcc[3];
	float m_fGyro[3];
	float m_fAngle[3];

	const uint32_t m_uiBaud[9] = {4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600};
};

extern ImuCapture ImuCaptureHandler;

#endif //IMU_CAPTURE_H
